package com.mzj.saas.mservice.lockManager.repository;

import com.mzj.saas.mservice.lockManager.entity.SmartLockUser;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface SmartLockUserRepository extends PagingAndSortingRepository<SmartLockUser, Long>, JpaSpecificationExecutor<SmartLockUser> {
    List<SmartLockUser> findByLockIdAndDelStatus(Long lockId, Integer delStatus);

    @Modifying
    @Query(value = "UPDATE saas_smart_lock_user u SET u.del_status = ?2 WHERE u.lock_id = ?1", nativeQuery = true)
    void updateDelStatusByLockId(Long lockId, Integer delStatus);

    int deleteByLockId(Long lockId);

    @Query(value = "SELECT * FROM saas_smart_lock_user WHERE (user_id = ?1 OR mobile = ?2) AND del_status = 1", nativeQuery = true)
    List<SmartLockUser> findPersonLockUser(String userId, String mobile);
}
